package collection;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import member2.Data;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MapInput extends JInternalFrame {
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JButton btnNewButton;
	private JTextField userID;
	private JTextField irum;
	private JTextField phone;
	private JTextField status;

	Map<String, MapData> map = new HashMap<String, MapData>();

	// /**
	// * Launch the application.
	// */
	// public static void main(String[] args) {
	// EventQueue.invokeLater(new Runnable() {
	// public void run() {
	// try {
	// MapInput frame = new MapInput();
	// frame.setVisible(true);
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }
	// });
	// }

	/**
	 * Create the frame.
	 */
	public MapInput(HashMap<String, MapData> a) {
		super("Input", true, true, true, false);
		this.map = a;

		setBounds(100, 100, 405, 204);
		getContentPane().setLayout(null);
		getContentPane().add(getLblNewLabel());
		getContentPane().add(getLblNewLabel_1());
		getContentPane().add(getLblNewLabel_2());
		getContentPane().add(getBtnNewButton());
		getContentPane().add(getUserID());
		getContentPane().add(getIrum());
		getContentPane().add(getPhone());
		getContentPane().add(getStatus());

	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("아이디");
			lblNewLabel.setBounds(39, 37, 57, 15);
		}
		return lblNewLabel;
	}

	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("성명");
			lblNewLabel_1.setBounds(39, 62, 57, 15);
		}
		return lblNewLabel_1;
	}

	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("연락처");
			lblNewLabel_2.setBounds(39, 87, 57, 15);
		}
		return lblNewLabel_2;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("입력");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// if (id.getText().equals("")) {
					// JOptionPane.showMessageDialog(null, "빈칸을 채우라고.");
					// return;
					// }
					//
					// MapData md = new MapData(id.getText(), irum.getText(),
					// phone.getText());
					// map.put(id.getText(), md);
					// result.setText("데이터가 저장되었습니다.");
					// id.setText("");
					// irum.setText("");
					// phone.setText("");
					// id.requestFocus();
					String id = userID.getText();
					String ir = irum.getText();
					String ph = phone.getText();
					if (id.equals("") || ir.equals("") || ph.equals("")) {
						status.setText("항목이 비어 있습니다.확인해주세요");

					} else {
						MapData d = new MapData(id, ir, ph);
						map.put(id, d);
						status.setText("데이터가 저장되었습니다");
					}

				}
			});
			btnNewButton.setBounds(251, 58, 97, 23);
		}
		return btnNewButton;
	}

	private JTextField getUserID() {
		if (userID == null) {
			userID = new JTextField();
			userID.setBounds(108, 34, 116, 21);
			userID.setColumns(10);
		}
		return userID;
	}

	private JTextField getIrum() {
		if (irum == null) {
			irum = new JTextField();
			irum.setBounds(108, 59, 116, 21);
			irum.setColumns(10);
		}
		return irum;
	}

	private JTextField getPhone() {
		if (phone == null) {
			phone = new JTextField();
			phone.setBounds(108, 84, 116, 21);
			phone.setColumns(10);
		}
		return phone;
	}

	private JTextField getStatus() {
		if (status == null) {
			status = new JTextField();
			status.setBounds(39, 134, 309, 21);
			status.setColumns(10);
		}
		return status;
	}
}
